package com.macro.mall.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsJobParam;
import com.macro.mall.mapper.BmsJobMapper;
import com.macro.mall.model.BmsJob;
import com.macro.mall.service.BmsJobService;
import com.macro.mall.utils.UserUtils;

import cn.hutool.core.date.DateTime;
@Service
public class BmsJobServiceImpl implements BmsJobService {
    
    @Autowired
    private BmsJobMapper bmsJobMapper;
    
    @Autowired
    private UserUtils userUtils;

    @Override
    public int create(BmsJobParam bmsJobParam) {
        BmsJob bmsJob = new BmsJob(); 
        BeanUtils.copyProperties(bmsJobParam, bmsJob);
        Long userId = userUtils.getUserId();
        bmsJob.setCreateUser(userId);
        bmsJob.setUpdateUser(userId);
        bmsJob.setCreateTime(new DateTime());
        bmsJob.setUpdateTime(new DateTime());
        int count = bmsJobMapper.insertJob(bmsJob);
        return count;
    }

    @Override
    public int update(BmsJobParam bmsJobParam) {
        BmsJob bmsJob = new BmsJob(); 
        BeanUtils.copyProperties(bmsJobParam, bmsJob);
        Long userId = userUtils.getUserId();
        bmsJob.setUpdateUser(userId);
        bmsJob.setUpdateTime(new DateTime());
        int count = bmsJobMapper.updateJob(bmsJob);
        return count;
    }

    @Override
    public List<BmsJob> getList(BmsJobParam bmsJobParam) {
        PageHelper.startPage(bmsJobParam.getPageNum(), bmsJobParam.getPageSize());
        BmsJob bmsJob = new BmsJob();
        bmsJob.setTitle(bmsJobParam.getTitle());
                
        return bmsJobMapper.list(bmsJob);
    }

    @Override
    public BmsJob getItem(Long id) {
        return bmsJobMapper.selectById(id);
    }

    @Override
    public int delete(List<Long> ids) {
        //获取当前登录用户id
        Long userId = userUtils.getUserId();
        
        int count = bmsJobMapper.updateDeleteId(ids,userId);
        return count;
    }

	@Override
	public List<BmsJob> getJobList() {
		List<BmsJob> list = bmsJobMapper.getJobList();
		return list;
	}

}
